## calling the installed package
train<- read.csv(file.choose()) ## Choose the train.csv file downloaded from the link above 
library(Rtsne)
## Curating the database for analysis with both t-SNE and PCA
Labels<-train$label
train$label<-as.factor(train$label)
## for plotting
colors = rainbow(length(unique(train$label)))
names(colors) = unique(train$label)

## Executing the algorithm on curated data
tsne <- Rtsne(train[,-1], dims = 3, perplexity=30, verbose=TRUE, max_iter = 500)
exeTimeTsne<- system.time(Rtsne(train[,-1], dims = 3, perplexity=30, verbose=TRUE, max_iter = 500))

## Plotting
plot(tsne$Y, t='n', main="tsne")
text(tsne$Y, labels=train$label, col=colors[train$label])


## Plot 3D
#library("scatterplot3d")
#scatterplot3d(tsne$Y, main = "3D barplot")
#text(tsne$Y, labels=train$label, col=colors[train$label])


